import { useRoutes, Navigate } from "react-router-dom";
import { RouteObject } from "./interface";
import Home from "@/pages/home";

const routerArray: RouteObject[] = [];
const pagesRouter = import.meta.globEager("./modules/*.tsx") as any;

Object.keys(pagesRouter).forEach(item => {
	Object.keys(pagesRouter[item]).forEach((key: any) => {
		routerArray.push(...pagesRouter[item][key]);
	});
});

export const rootRouter: RouteObject[] = [
	{
		path: "/",
		element: <Home />
	},

	...routerArray,
	{
		path: "*",
		element: <Navigate to="/404" />
	}
];

const Page = () => {
	return <>{useRoutes(rootRouter)}</>;
};

export default Page;
